/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package algorithm;

import java.util.ArrayList;

/**
 *
 * @author Nuf
 */
public class Solution {

    private ArrayList<ArrayList<WorkingTask>> solution;
    private int numberOfResources;
    private int solutionEvaluation;

    public Solution(int numberOfResources){
        this.numberOfResources = numberOfResources;
        solution = new ArrayList<>();
        for(int i=0;i<numberOfResources;i++){
            solution.add(new ArrayList<WorkingTask>());
        }
        this.solutionEvaluation = -1;
    }

    public ArrayList<ArrayList<WorkingTask>> getSolution() {
        return solution;
    }

    public void setSolution(ArrayList<ArrayList<WorkingTask>> solution) {
        this.solution = solution;
        this.solutionEvaluation = fitness();
    }
    public int getNumberOfResources() {
        return numberOfResources;
    }

    public int getSolutionEvaluation() {
        return solutionEvaluation;
    }

    private int fitness() {
        
        int longestTime = solution.get(0).get(solution.get(0).size()-1).getEndTime();
        for(ArrayList<WorkingTask> resource : solution){
            for(WorkingTask task : resource){
                if(task.getEndTime() > longestTime){
                    longestTime = task.getEndTime();
                }
            }
        }
        return longestTime;
    }
    
    private int getSize(){
        int size = 0;
        for(ArrayList<WorkingTask> resource : solution){
            size += resource.size();
        }
        return size;
    }
            


    public String toString() {
        String s = "Solution : "+getSize()+" tâches, temps max = "+solutionEvaluation+"\n";
        for (int i = 0; i < solution.size(); i++) {
            for (WorkingTask w : solution.get(i)) {
                s = s.concat(w.getStartTime() + "-" + w.getEndTime() + "(r="+w.getRessourceUsed()+"m=" + w.getMachineUsed() + "p=" + w.getProductUsed() + ")" + " | ");
            }
            s = s.concat("\n");
        }
        return s;
    }
}
